﻿using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.BusinessLogicLayer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CuaHangMayTinh.PresentationLayer
{
    /// <summary>
    /// Enum Report các danh sách theo các yêu cầu
    /// </summary>
    public enum ReportList
    {
        NhaCungCap,
        NhanVien,
        ModelMatHang
    };

    public partial class FormReportList : Form
    {
        ReportList rl = ReportList.NhaCungCap;

        List<NhaCungCapEntity> listncc = new List<NhaCungCapEntity>();
        List<NhanVienEntity> listnhanvien = new List<NhanVienEntity>();
        List<NghiepVuEntity> listnghiepvu = new List<NghiepVuEntity>();
        List<InfoEntity> listinfo = InfoManager.ConvertToList(InfoManager.GetThongTin());
        List<ModelMatHangEntity> listmodel = new List<ModelMatHangEntity>();

        /// <summary>
        /// Khởi tạo form report hiển thị danh sách Nhà Cung Cấp
        /// </summary>
        public FormReportList(List<NhaCungCapEntity> list)
            : this()
        {
            listncc = list;
            rl = ReportList.NhaCungCap;
        }

        /// <summary>
        /// Khởi tạo form report hiển thị danh sách Nhân Viên
        /// </summary>
        public FormReportList(List<NhanVienEntity> listnv, List<NghiepVuEntity> listngv)
            : this()
        {
            listnhanvien = listnv;
            listnghiepvu = listngv;
            rl = ReportList.NhanVien;
        }


        public FormReportList(List<ModelMatHangEntity> models)
            : this()
        {
            listmodel = models;
            rl = ReportList.ModelMatHang;
        }


        public FormReportList()
        {
            InitializeComponent();
        }


        private void FormReportList_Load(object sender, EventArgs e)
        {
            switch (rl)
            {
                case ReportList.NhaCungCap:
                    ReportNhaCungCap();
                    break;
                case ReportList.NhanVien:
                    ReportNhanVien();
                    break;
                case ReportList.ModelMatHang:
                    ReportModel();
                    break;
                default:
                    this.reportViewer1.RefreshReport();
                    break;
            }
        }

        /// <summary>
        /// Hàm hiển thị danh sách nhà cung cấp lên reportViewer
        /// </summary>
        void ReportNhaCungCap()
        {
            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "CuaHangMayTinh.PresentationLayer.Report.ListNhaCungCapReport.rdlc"; // bind reportviewer with .rdlc

            Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("NhaCungCapDataSet", listncc); // set the datasource

            reportViewer1.LocalReport.DataSources.Add(dataset);
            dataset.Value = listncc;

            reportViewer1.LocalReport.Refresh();
            reportViewer1.RefreshReport(); // refresh report
        }

        /// <summary>
        /// Hàm hiển thị danh sách nhân viên lên reportViewer
        /// </summary>
        void ReportNhanVien()
        {
            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "CuaHangMayTinh.PresentationLayer.Report.ListNhanVienReport.rdlc"; // bind reportviewer with .rdlc

            Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("NhanVienDataSet", listnhanvien); // set the datasource
            Microsoft.Reporting.WinForms.ReportDataSource dataset1 = new Microsoft.Reporting.WinForms.ReportDataSource("NghiepVuDataSet", listnghiepvu); // set the datasource

            reportViewer1.LocalReport.DataSources.Add(dataset);
            reportViewer1.LocalReport.DataSources.Add(dataset1);

            dataset.Value = listnhanvien;
            dataset1.Value = listnghiepvu;

            reportViewer1.LocalReport.Refresh();
            reportViewer1.RefreshReport(); // refresh report
        }

        void ReportModel()
        {
            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "CuaHangMayTinh.PresentationLayer.Report.ListModelMatHang.rdlc"; // bind reportviewer with .rdlc

            Microsoft.Reporting.WinForms.ReportDataSource modelds = new Microsoft.Reporting.WinForms.ReportDataSource("ModelMatHangDataSet", listmodel); // set the datasource
            Microsoft.Reporting.WinForms.ReportDataSource infods = new Microsoft.Reporting.WinForms.ReportDataSource("InfoDataSet", listinfo); // set the datasource

            reportViewer1.LocalReport.DataSources.Add(modelds);
            reportViewer1.LocalReport.DataSources.Add(infods);

            modelds.Value = listmodel;
            infods.Value = listinfo;

            reportViewer1.LocalReport.Refresh();
            reportViewer1.RefreshReport(); // refresh report
        }
    }
}
